package com.tonann.app.mqtt.config;

import com.tonann.app.domain.AppSensor;
import com.tonann.app.mqtt.dao.MQTTSensor;
import com.tonann.app.service.IAppSensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;
import java.util.List;

//@Configuration
public class AppSensorInitConf {
    @Resource
    private IAppSensorService sensorService;

    @Bean
    public void init() {
        List<AppSensor> appSensorList = sensorService.selectAppSensorListByGatewayType("2");
        for (AppSensor sensor : appSensorList) {
            String tag = sensor.getMqttDeviceChannel() + "." + sensor.getMqttDeviceName() + "." + sensor.getMqttDeviceTag();
            MQTTSensor.getInstance().map.put(tag, sensor);
            MQTTSensor.getInstance().topicSet.add(sensor.getMqttTopic());
        }
    }
}
